using RimWorld;
using Verse;
using Verse.Sound;

namespace RimZombieGirl
{
    public class CompProperties_SoulCapture : CompProperties_AbilityEffect
    {
        // 可扩展参数，例如stun时长
        public int stunDurationTicks = 600; // 10秒（1秒=60ticks）

        // 播放声音
        public SoundDef soundCast;

        public CompProperties_SoulCapture()
        {
            compClass = typeof(CompAbilityEffect_SoulCapture);
        }
    }

    public class CompAbilityEffect_SoulCapture : CompAbilityEffect
    {
        public new CompProperties_SoulCapture Props => (CompProperties_SoulCapture)props;

        public override void Apply(LocalTargetInfo target, LocalTargetInfo dest)
        {
            base.Apply(target, dest);
            Pawn pawn = target.Pawn;
            if (pawn == null)
            {
                return;
            }
            // 调用逻辑方法
            ApplySoulCaptureEffect(pawn, Props.stunDurationTicks);
            // 播放声音
            if (Props.soundCast != null)
            {
                Props.soundCast.PlayOneShot(new TargetInfo(pawn.Position, pawn.Map));
            }
        }

        // 调用逻辑方法
        public void ApplySoulCaptureEffect(Pawn caster, int durationTicks)
        {
            // 获取所有诅咒Hediff
            var cursedHediffs = CachedHediff.GetAllByHediffs(RIHediffDefOf.RI_He_BloodCurse);

            // 遍历其中link为自身的
            foreach (var kvp in cursedHediffs)
            {
                var target = kvp.Key;
                var cached = kvp.Value;
                if (cached.LinkPawn == caster)
                {
                    // 对其进行stun
                    if (target.stances != null)
                    {
                        target.stances.stunner.StunFor(durationTicks, null, true, true);
                    }
                }
            }

            
        }
    }
}
